FROM {{ rocketmq.build_image }} AS builder

WORKDIR /build

COPY ./settings.xml /root/.m2/settings.xml
VOLUME /root/.m2

RUN apt-get update && \
    apt-get install -y wget unzip && \
    wget https://archive.apache.org/dist/rocketmq/{{ rocketmq.version }}/rocketmq-all-{{ rocketmq.version }}-source-release.zip && \
    unzip rocketmq-all-{{ rocketmq.version }}-source-release.zip && \
    cd rocketmq-all-{{ rocketmq.version }}-source-release && \
    {{ build_cmd }}

FROM openjdk:8-jre-alpine

COPY --from=builder /build/rocketmq-all-{{ rocketmq.version }}-source-release/distribution/target/rocketmq-{{ rocketmq.version }}/rocketmq-{{ rocketmq.version }} /opt/rocketmq